﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;
using RemoteObject;

namespace RemoteClient.UI
{
    public partial class UJobItem : ListViewItem
    {

        private UploadRequestor uJob;

        private ListViewSubItem nameItem;
        private ListViewSubItem processItem;
        private ListViewSubItem rateItem;
        private ListViewSubItem stateItem;

        public UploadRequestor UJob
        {
            get
            {
                return uJob;
            }
            set
            {
                uJob = value;
                InitSubItems();
            }
        }
        
        public UJobItem(UploadRequestor uJob)
        {
            UJob = uJob;            
        }

        private void InitSubItems()
        {
            nameItem = new ListViewSubItem(this, uJob.GetJobName());
            processItem = new ListViewSubItem(this, uJob.GetProgress().ToString("f2") + "%");
            rateItem = new ListViewSubItem(this, uJob.GetDownloadSpeed().ToString("f2") + " KB/s");
            stateItem = new ListViewSubItem(this, uJob.GetStatus().ToString());

            SubItems.Clear();
            SubItems.Insert(0, nameItem);
            SubItems.Insert(1, processItem);
            SubItems.Insert(2, rateItem);
            SubItems.Insert(3, stateItem);
        }

        
        public void RefreshJobInfo()
        {
            processItem.Text = uJob.GetProgress().ToString("f2") + "%";
            rateItem.Text = uJob.GetDownloadSpeed().ToString("f2") + " KB/s";
            stateItem.Text = uJob.GetStatus().ToString();
        }        
    }
}
